<template>
    <div class="content-container">
        <Title :icon="'chat-poll-fill'" :title="'各平台问题占比'"></Title>
        <div class="h-290px overflow-hidden ml-16px mr-16px">
            <table class="distillation-table">
                <tr>
                    <th width="20%">平台</th>
                    <th width="20%">占比</th>
                    <th width="10%">数量</th>
                    <th width="20%">平台</th>
                    <th width="20%">占比</th>
                    <th width="10%">数量</th>
                </tr>
            </table>
            <el-scrollbar :always="true">
                <table class="distillation-table">
                    <tr v-for="(row, index) in tableDataRows" :key="index">
                        <td width="20%">{{ row.item1.Name }}</td>
                        <td width="20%">{{ row.item1.Proportion }}</td>
                        <td width="10%">{{ row.item1.Value }}</td>
                        <td width="20%" v-if="row.item2">{{ row.item2.Name }}</td>
                        <td width="20%" v-if="row.item2">{{ row.item2.Proportion }}</td>
                        <td width="10%" v-if="row.item2">{{ row.item2.Value }}</td>
                    </tr>
                </table>
            </el-scrollbar>
        </div>
    </div>
</template>

<script setup lang="ts">
import Title from '@/components/Title/index.vue'
import { getPlatformQuestionApi } from '@/api/geo/index'
import { IProblem } from '@/api/geo/types'

const state = reactive({
    problemData: <IProblem[]>[]
})

// 将数据转换为每行显示两条数据的格式
const tableDataRows = computed(() => {
    const rows = []
    for (let i = 0; i < state.problemData.length; i += 2) {
        const item1 = state.problemData[i]
        const item2 = i + 1 < state.problemData.length ? state.problemData[i + 1] : null
        rows.push({ item1, item2 })
    }
    return rows
})

async function getPlatformQuestion(){
    const res:ResType = await getPlatformQuestionApi("/GEOApi/GetKeywordProportion")
    if(res.code === 200){
        state.problemData = res.dataAll
    }  
}

onMounted(() => {
    getPlatformQuestion()
})
</script>

<style scoped>

</style>